﻿using System;
using System.Web.Mvc;
using StructureMap;
using Quickie.Models;
using Quickie.Models.IoC;
using Quickie.Models.Data;
using Quickie.Models.Entities;
using Quickie.Models.ViewModel;
using Quickie.Models.Interfaces;

namespace Quickie.Models.IoC
{
    /// <summary>
    /// Klasa ControllerFactory
    /// </summary>
    public class ControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            IController controller = null;
            if (controllerType == null)
                return null;
            
            try
            {
                controller = ObjectFactory.GetInstance(controllerType) as IController;
            }
            catch (StructureMapException ex)
            {
                System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                throw;
            }

            return controller;
        }
    }
}
